import 'package:fluttercalcpokers/util/comm_util.dart';

import 'bean/card_bean.dart';
import 'bean/player_bean.dart';
import 'bean/texas_bean.dart';
import 'card_util.dart';

class CardPowerUtils {
  ///获取十进制的牌力整型
  static int getCardPowerInt(PlayerBean playerBean, TexasBean curBean) {
    var cardType = CardUtils.recogniseType(playerBean, curBean);
    List<CardBean> cardResults =
        CardUtils.getCardResultList(playerBean, curBean);
    String strengthHex = getCardPower(cardType, cardResults);
    return CommUtils.hexToInt(strengthHex);
  }

  ///获取十六进制的牌力字符串
  static String getCardPower(int type, List<CardBean> list) {
    var powerString;
    switch (type) {
      case 0:
        powerString = getHighPower(list);
        break;
      case 1:
        powerString = getPairPower(list);
        break;
      case 2:
        powerString = getTwoPairPower(list);
        break;
      case 3:
        powerString = getTripsPower(list);
        break;
      case 4:
        powerString = getStraightPower(list);
        break;
      case 5:
        powerString = getFlushPower(list);
        break;
      case 6:
        powerString = getFullHousePower(list);
        break;
      case 7:
        powerString = getQuadsPower(list);
        break;
      case 8:
        powerString = getFlushStraightPower(list);
        break;
      case 9:
        powerString = getRoyalFlushStraightPower(list);
        break;
      default:
        powerString = new List();
    }
    return powerString;
  }

  static String getHighPower(List<CardBean> list) {
    String power = "0";
    for (var card in list) {
      power += getNumStr(card.num);
    }
    return power;
  }

  static String getPairPower(List<CardBean> list) {
    String power = "1";
    power += getNumStr(list.first.num);
    for (var i = 2; i < 5; i++) {
      power += getNumStr(list[i].num);
    }
    power += "0";
    return power;
  }

  static String getTwoPairPower(List<CardBean> list) {
    String power = "2";
    power += getNumStr(list.first.num);
    power += getNumStr(list[2].num);
    power += getNumStr(list[4].num);
    power += "00";
    return power;
  }

  static String getTripsPower(List<CardBean> list) {
    String power = "3";
    power += getNumStr(list.first.num);
    power += getNumStr(list[3].num);
    power += getNumStr(list[4].num);
    power += "00";
    return power;
  }

  static String getStraightPower(List<CardBean> list) {
    String power = "4";
    power += getNumStr(list.first.num);
    power += "0000";
    return power;
  }

  static String getFlushPower(List<CardBean> list) {
    String power = "5";
    power += getNumStr(list.first.num);
    power += "0000";
    return power;
  }

  static String getFullHousePower(List<CardBean> list) {
    String power = "6";
    power += getNumStr(list.first.num);
    power += getNumStr(list[3].num);
    power += "000";
    return power;
  }

  static String getQuadsPower(List<CardBean> list) {
    String power = "7";
    power += getNumStr(list.first.num);
    power += "0000";
    return power;
  }

  static String getFlushStraightPower(List<CardBean> list) {
    String power = "8";
    power += getNumStr(list.first.num);
    power += "0000";
    return power;
  }

  static String getRoyalFlushStraightPower(List<CardBean> list) {
    String power = "9";
    power += "00000";
    return power;
  }

  static String getNumStr(int num) {
    if (num == 10) {
      return "A";
    } else if (num == 11) {
      return "B";
    } else if (num == 12) {
      return "C";
    } else if (num == 13) {
      return "D";
    } else if (num == 14) {
      return "E";
    } else {
      return num.toString();
    }
  }
}
